/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package root;

import Grafik.GrafikObject;
import Grafik.GrafikRectangle;
import Grafik.GrafikTriangle;
import java.util.ArrayList;

/**
 *
 * @author Bernhard
 */
public class Controler {

    private static Controler control;
    private static double scale = 2;

    private ArrayList<GrafikObject> objects = new ArrayList<GrafikObject>();

    private Controler(){
    }
    
    
    
    

    public static Controler getInstance(){
        if (control == null){
            control = new Controler();
        }
        return control;
    }
    
    public ArrayList<GrafikObject> getObjects(){
        return this.objects;
    }

    public ArrayList<GrafikObject> getObjectsList(){
        return objects;
    }
    
    public static double getScale(){
        return scale;
    }

    public static void setScale(double scale){
        Controler.scale = scale;
    }

    public void addGrafikObject(GrafikObject g){
        objects.add(g);
    }

    public void clearList(){
        objects.clear();
    }
    
    public int maxX(){
        int maxX = 1;
        for (GrafikObject object : objects){
            if (object instanceof GrafikRectangle){
                GrafikRectangle obj = (GrafikRectangle) object;
                if (obj.getA().getX() > maxX){
                   maxX = obj.getA().getX(); 
                }   
                if (obj.getB().getX() > maxX){
                   maxX = obj.getB().getX(); 
                }   
                if (obj.getC().getX() > maxX){
                   maxX = obj.getC().getX(); 
                }   
                if (obj.getD().getX() > maxX){
                   maxX = obj.getD().getX(); 
                }   
            }
            
            if (object instanceof GrafikTriangle){
                GrafikTriangle obj = (GrafikTriangle) object;
                if (obj.getA().getX() > maxX){
                   maxX = obj.getA().getX(); 
                }   
                if (obj.getB().getX() > maxX){
                   maxX = obj.getB().getX(); 
                }   
                if (obj.getC().getX() > maxX){
                   maxX = obj.getC().getX(); 
                }   
            }
        }
        
        return maxX;
    }
    
    public int maxY(){
        int maxY = 1;
        for (GrafikObject object : objects){
            if (object instanceof GrafikRectangle){
                GrafikRectangle obj = (GrafikRectangle) object;
                if (obj.getA().getY() > maxY){
                   maxY = obj.getA().getY(); 
                }   
                if (obj.getB().getY() > maxY){
                   maxY = obj.getB().getY(); 
                }   
                if (obj.getC().getY() > maxY){
                   maxY = obj.getC().getY(); 
                }   
                if (obj.getD().getY() > maxY){
                   maxY = obj.getD().getY(); 
                }   
            }
            
            if (object instanceof GrafikTriangle){
                GrafikTriangle obj = (GrafikTriangle) object;
                if (obj.getA().getY() > maxY){
                   maxY = obj.getA().getY(); 
                }   
                if (obj.getB().getY() > maxY){
                   maxY = obj.getB().getY(); 
                }   
                if (obj.getC().getY() > maxY){
                   maxY = obj.getC().getY(); 
                }   
            }
        }
        
        return maxY;
    }
}
